﻿namespace AnyOffice.general.netmeeting.attend
{
    using AjaxPro;
    using AnyOffice.Components;
    using AnyOffice.DAL;
    using AnyOffice.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;

    public class AjaxMethods
    {
        [AjaxMethod]
        public DataSet GetMessage(int sessionId)
        {
            SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
            NetMeetingMessagesDao dao = new NetMeetingMessagesDao();
            DataSet dataSet = dao.GetMessage(connection, sessionId, HttpContext.Current.User.Identity.Name).DataSet;
            if (connection.State == ConnectionState.Open) connection.Close();
            return dataSet;
        }

        [AjaxMethod]
        public DataSet GetOnline(int sessionId)
        {
            SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
            NetMeetingUserDao dao = new NetMeetingUserDao();
            DataSet dataSet = dao.SelectOnline(connection, sessionId).DataSet;
            if (connection.State == ConnectionState.Open) connection.Close();
            return dataSet;
        }

        [AjaxMethod]
        public void SendMessage(int sessionId, string toId, string color, bool isPrivate, string content)
        {
            SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
            NetMeetingMessagesDao dao = new NetMeetingMessagesDao();
            NetMeetingMessagesData data = new NetMeetingMessagesData();


            data.SessionId = sessionId;

            data.ToId = toId;

            data.Color = color;

            data.IsPrivate = isPrivate;

            data.Content = content;
            dao.Insert(connection, data);
            if (connection.State == ConnectionState.Open) connection.Close();
        }
    }
}

